home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 November / Chip Kasım 2000.iso / prog / share / 11 / setup.exe / %MAINDIR% / DEMOS / CISERVER / CHAT / CHATHOST / frmHost.frm (.txt) < prev   
Encoding:
Visual Basic Form  |  2000-09-07  |  6.4 KB  |  179 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Chat Server"
  4.    ClientHeight    =   3600
  5.    ClientLeft      =   3165
  6.    ClientTop       =   1560
  7.    ClientWidth     =   4605
  8.    Height          =   4080
  9.    Left            =   3105
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   3600
  12.    ScaleWidth      =   4605
  13.    Top             =   1140
  14.    Width           =   4725
  15.    Begin VB.TextBox txtPort 
  16.       Height          =   285
  17.       Left            =   90
  18.       TabIndex        =   5
  19.       Text            =   "2000"
  20.       Top             =   1170
  21.       Width           =   1365
  22.    End
  23.    Begin VB.CommandButton cmdStart 
  24.       Caption         =   "Start Chat Server"
  25.       Height          =   375
  26.       Left            =   90
  27.       TabIndex        =   4
  28.       Top             =   1800
  29.       Width           =   1365
  30.    End
  31.    Begin VB.ListBox lstNames 
  32.       Height          =   3180
  33.       Left            =   1710
  34.       TabIndex        =   2
  35.       Top             =   360
  36.       Width           =   2805
  37.    End
  38.    Begin VB.TextBox txtConnections 
  39.       Height          =   315
  40.       Left            =   90
  41.       TabIndex        =   1
  42.       Text            =   "10"
  43.       Top             =   360
  44.       Width           =   1365
  45.    End
  46.    Begin VB.Label Label3 
  47.       Caption         =   "Port Number:"
  48.       Height          =   195
  49.       Left            =   90
  50.       TabIndex        =   6
  51.       Top             =   900
  52.       Width           =   1455
  53.    End
  54.    Begin VB.Label Label2 
  55.       Caption         =   "Currently connected:"
  56.       Height          =   285
  57.       Left            =   1710
  58.       TabIndex        =   3
  59.       Top             =   90
  60.       Width           =   2445
  61.    End
  62.    Begin CISERVERLib.CIServer svrChat 
  63.       Left            =   540
  64.       Top             =   2880
  65.       _Version        =   65536
  66.       _ExtentX        =   847
  67.       _ExtentY        =   794
  68.       _StockProps     =   0
  69.    End
  70.    Begin VB.Label Label1 
  71.       Caption         =   "Max. Connections:"
  72.       Height          =   195
  73.       Left            =   90
  74.       TabIndex        =   0
  75.       Top             =   90
  76.       Width           =   1455
  77.    End
  78. Attribute VB_Name = "Form1"
  79. Attribute VB_Creatable = False
  80. Attribute VB_Exposed = False
  81. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  82. '~~~ SUBJECT:     Crescent Internet ToolPak CISERVER Client Demo
  83. '~~~ AUTHOR:      Bob Follet
  84. '~~~ DATE:        December 1, 1997
  85. '~~~ MODIFIED:
  86. '~~~ DESCRIPTION: Crescent Internet ToolPak CISERVER Server Demo.  This Demo provides
  87. '~~~              details on how to use the CISERVER Control.  This demo receives
  88. '~~~              messages from the CISERVER Client Demo and returns a response. See
  89. '~~~              The CISERVER Chat Demo for further information.
  90. '~~~ ADDITIONS:   No Additions. This is a New Demo to Internet ToolPak
  91. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  92. Dim MaxClients As Integer
  93. Private Sub cmdStart_Click()
  94. ' Start Running the Server
  95. Dim temp As Variant
  96. If svrChat.ListenMode = 0 Then 'Will not accept connections if 0
  97.     MaxClients = Val(txtConnections.Text) ' maximum number of connections to server
  98.     temp = Int(Val(txtPort.Text))
  99.     'Determine if port number is valid
  100.     If temp < -32768 Or temp > 32767 Or temp = 0 Then 'invalid port
  101.         MsgBox "Port number must be between -32768 and 32767 excluding the value of zero", 0, "Invalid Parameter"
  102.         txtPort.SelStart = 0
  103.         txtPort.SelLength = Len(txtPort.Text)
  104.         txtPort.SetFocus
  105.         Exit Sub
  106.     End If
  107.     svrChat.Port = temp
  108.     svrChat.ListenMode = 1 'start accepting connections
  109.     cmdStart.Caption = "Exit"
  110. Else 'Exit application
  111.     If svrChat.Clients.Count <> 0 Then
  112.         i = MsgBox("There are still active connections.  Are you sure you want to Exit?", 4)
  113.         If i = vbYes Then End
  114.     Else
  115.         End
  116.     End If
  117. End If
  118.        
  119. End Sub
  120. Private Sub svrChat_ClientSocketError(ByVal FromClient As Object, ByVal ErrorNumber As Integer)
  121. ' An Error was generated, display results
  122. Debug.Print "ClientSocketError  from " & FromClient.Address & " Error number= " & ErrorNumber
  123. End Sub
  124. Private Sub svrChat_ConnectionAttempt(ByVal NewClient As Object, AcceptConnection As Boolean)
  125. 'test if maximum connections has been reached
  126. If svrChat.Clients.Count = MaxClients Then 'deny connecion
  127.     NewClient.Send "Sorry, No more connections accepted at this time"
  128.     AcceptConnection = False
  129. End If
  130. End Sub
  131. Private Sub svrChat_PacketReceived(ByVal FromClient As Object, Packet As Variant, ByVal BytesRec As Integer)
  132. Dim x As Client
  133. Dim i As Integer
  134. Dim message As String
  135. ' Check if a client is sending a chat message, its ScreenName or is disconnecting.
  136. ' ~| is used by this demo to denote a message to the server when a client
  137. '  is sending its screen name or is disconnecting.  Any other packet is
  138. '  distributed as a chat message
  139. If InStr(Packet, "~|") Then
  140.     If InStr(Packet, "name") Then 'client is sending screen name
  141.         lstNames.AddItem Right(Packet, Len(Packet) - 7)
  142.         'send name list to all client
  143.         message = "<Names>"
  144.         For i = 0 To lstNames.ListCount - 1
  145.             message = message & lstNames.List(i) & Chr(13)
  146.         Next i
  147.         ' Display the message to each client who is connected, in the collection.
  148.         For Each x In svrChat.Clients
  149.             x.Send message
  150.         Next
  151.     ElseIf InStr(Packet, "exit") Then 'test for disconnect
  152.         'remove screen name from listbox
  153.         For i = 0 To lstNames.ListCount
  154.             If Right$(Packet, Len(Packet) - 6) = lstNames.List(i) Then
  155.                 lstNames.RemoveItem i
  156.                 Exit For
  157.             End If
  158.         Next i
  159.         'create new list of screen names
  160.         message = "<Names>"
  161.         For i = 0 To lstNames.ListCount - 1
  162.             message = message & lstNames.List(i) & Chr(13)
  163.         Next i
  164.         'send new list of screen names to all clients
  165.         For Each x In svrChat.Clients
  166.             x.Send message
  167.         Next
  168.     End If
  169. Else ' Chat message > forward to all clients connected
  170.     For Each x In svrChat.Clients
  171.         x.Send Packet
  172.     Next
  173. End If
  174. End Sub
  175. Private Sub svrChat_SocketError(ByVal ErrorNumber As Integer)
  176. ' An error was detected, display results.
  177. Debug.Print "SocketError #" & ErrorNumber & " occured"
  178. End Sub
  179.